home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / NotificationMon ƒ / NotificationMon.ƒ / Source / DialogUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-22  |  3.3 KB  |  200 lines  |  [TEXT/KAHL]

  1. /*
  2.     DialogUtil.c
  3.     ------------
  4. */
  5.  
  6. #ifndef NIL
  7. #define NIL    0L
  8. #endif
  9.  
  10. #ifndef THE_FRONT_WINDOW
  11. #define THE_FRONT_WINDOW (Ptr)(void *) -1L
  12. #endif
  13.  
  14. pascal void HiliteItemProc(WindowPtr wp, short item)
  15. {
  16.     HilightItem(wp,item);
  17. }
  18.  
  19. SetUserItemProc(DialogPtr dp, short item, ProcPtr proc)
  20. {
  21.     Handle    iHandle;
  22.     Rect    box;
  23.     int        iType;
  24.     Str255    tempString;
  25.     long    itemValue;
  26.     
  27.     GetDItem(dp,item,&iType,&iHandle,&box);
  28.     SetDItem(dp,item,iType,(Handle)proc,&box);
  29. }
  30.  
  31. PutNumericItem(theDialog,itemNumber,number)
  32. DialogPtr    theDialog;
  33. short            itemNumber;
  34. short            number;
  35. {
  36.     Handle    iHandle;
  37.     Rect    box;
  38.     int        iType;
  39.     Str255    tempString;
  40.     long    itemValue;
  41.     
  42.     NumToString(number,&tempString);
  43.     GetDItem(theDialog,itemNumber,&iType,&iHandle,&box);
  44.     SetIText(iHandle,&tempString);
  45. }
  46.  
  47. short GetNumericItem(theDialog,itemNumber)
  48. DialogPtr    theDialog;
  49. int            itemNumber;
  50.  
  51. {
  52.     Handle    iHandle;
  53.     Rect    box;
  54.     int        iType;
  55.     Str255    tempString;
  56.     long    itemValue;
  57.     
  58.     GetDItem(theDialog,itemNumber,&iType,&iHandle,&box);
  59.     GetIText(iHandle,&tempString);
  60.     StringToNum(&tempString,&itemValue);
  61.     return(itemValue);
  62. }
  63.  
  64. GetTextItem(theDialog,itemNumber,text)
  65. DialogPtr    theDialog;
  66. int            itemNumber;
  67. Str255        *text;
  68. {
  69.     Handle    iHandle;
  70.     Rect    box;
  71.     int        iType;
  72.     
  73.     GetDItem(theDialog,itemNumber,&iType,&iHandle,&box);
  74.     GetIText(iHandle,text);
  75. }
  76.  
  77. PutTextItem(theDialog,itemNumber,text)
  78. DialogPtr    theDialog;
  79. int            itemNumber;
  80. Str255        *text;
  81. {
  82.     Handle    iHandle;
  83.     Rect    box;
  84.     int        iType;
  85.     
  86.     GetDItem(theDialog,itemNumber,&iType,&iHandle,&box);
  87.     SetIText(iHandle,text);
  88. }
  89.  
  90. ShowDialog(dialog_id)
  91. int    dialog_id;
  92. {
  93.     DialogPtr    dialog_ptr;
  94.     int            itemHit;
  95.     
  96.     dialog_ptr = GetNewDialog(dialog_id,NIL,THE_FRONT_WINDOW);
  97.     ModalDialog(NIL,&itemHit);
  98.     DisposDialog(dialog_ptr);
  99. }
  100.  
  101. int GetDialogCtlValue(dialog,item)
  102. DialogPtr    dialog;
  103. int            item;
  104. {
  105.     ControlHandle        iHandle;
  106.     Rect                box;
  107.     int                    iType;
  108.  
  109.     GetDItem(dialog,item,&iType,&iHandle,&box);
  110.     return(GetCtlValue(iHandle));
  111. }
  112.  
  113. SetDialogCtlValue(dialog,item,newValue)
  114. DialogPtr    dialog;
  115. int            item;
  116. {
  117.     ControlHandle        iHandle;
  118.     Rect                box;
  119.     int                    iType;
  120.  
  121.     GetDItem(dialog,item,&iType,&iHandle,&box);
  122.     SetCtlValue(iHandle,newValue);
  123. }
  124.  
  125. SetDialogCtlHilite(dialog,item,hilite)
  126. DialogPtr    dialog;
  127. short        item;
  128. short        hilite;
  129. {
  130.     ControlHandle        iHandle;
  131.     Rect                box;
  132.     int                    iType;
  133.  
  134.     GetDItem(dialog,item,&iType,&iHandle,&box);
  135.     HiliteControl(iHandle,hilite);
  136. }
  137.  
  138. void BoxItem(dialog,item)
  139. DialogPtr    dialog;
  140. int            item;
  141. {
  142.     Handle        iHandle;
  143.     Rect        box;
  144.     int            iType;
  145.     GrafPtr        savePort;
  146.     
  147.     GetPort(&savePort);
  148.     SetPort(dialog);
  149.     GetDItem(dialog,item,&iType,&iHandle,&box);
  150.     InsetRect(&box,-2,-2);
  151.     FrameRect(&box);
  152.     SetPort(savePort);
  153. }
  154.  
  155. HilightItem(dialog,item)
  156. DialogPtr    dialog;
  157. int            item;
  158. {
  159.     Handle        iHandle;
  160.     Rect        box;
  161.     int            iType;
  162.     PenState    savePen;
  163.     GrafPtr        savePort;
  164.     
  165.     GetPort(&savePort);
  166.     SetPort(dialog);
  167.     GetPenState(&savePen);
  168.     GetDItem(dialog,item,&iType,&iHandle,&box);
  169.     PenSize(3,3);
  170.     InsetRect(&box,-4,-4);
  171.     FrameRoundRect(&box,16,16);
  172.     SetPenState(&savePen);
  173.     SetPort(savePort);
  174. }
  175.  
  176.  
  177.  
  178. int TrackDialogControl(dialog,item,start)
  179. DialogPtr     dialog;
  180. int            item;
  181. Point        start;
  182. {
  183.     Handle        cHandle;
  184.     Rect        box;
  185.     int            iType;
  186.  
  187.     GetDItem(dialog,item,&iType,&cHandle,&box);
  188.     return(TrackControl(cHandle,start,NIL));
  189. }
  190.  
  191. GetDbox(dialog,item,box)
  192. DialogPtr    dialog;
  193. int            item;
  194. Rect        *box;
  195. {
  196.     Handle        iHandle;
  197.     int            iType;
  198.  
  199.     GetDItem(dialog,item,&iType,&iHandle,box);
  200. }